using System;
using System.Collections.Generic;

namespace DemoClasses;

/// <summary>
/// Calculator with basic arithmetic operations and history tracking
/// </summary>
public class Calculator
{
    private readonly List<string> _history;
    private double _lastResult;

    public double LastResult => _lastResult;
    public int OperationCount => _history.Count;

    public Calculator()
    {
        _history = new List<string>();
        _lastResult = 0.0;
    }

    public double Add(double a, double b)
    {
        double result = a + b;
        _lastResult = result;
        _history.Add($"{a} + {b} = {result}");
        return result;
    }

    public double Subtract(double a, double b)
    {
        double result = a - b;
        _lastResult = result;
        _history.Add($"{a} - {b} = {result}");
        return result;
    }

    public double Multiply(double a, double b)
    {
        double result = a * b;
        _lastResult = result;
        _history.Add($"{a} * {b} = {result}");
        return result;
    }

    public double Divide(double a, double b)
    {
        if (Math.Abs(b) < 0.0001)
            throw new DivideByZeroException("Cannot divide by zero");

        double result = a / b;
        _lastResult = result;
        _history.Add($"{a} / {b} = {result}");
        return result;
    }

    public List<string> GetHistory()
    {
        return new List<string>(_history);
    }

    public void ClearHistory()
    {
        _history.Clear();
    }
}
